package dyyx.demo;
import java.time.LocalDateTime;
import java.util.Date;

import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;

import dyyx.util.CommUtil;

public class MVStoreWriteTest {
	
	private static final int num = CommUtil.getNumFromSysProp();


	public static void main(String[] args) throws Exception {
		System.out.println("hello,MVStoreWriteTest,"+new Date());
		
		String home = CommUtil.getUserHome();
		System.out.println("home="+home);
		String fileName = home+"/h2/001.data";
		
		//  java.lang.IllegalArgumentException: Directory does not exist: nio:/Users/dugang/h2 [1.4.200/0]
		MVStore s = MVStore.open(fileName);
		

		MVMap<Integer, String> map = s.openMap("data");
		
		System.out.println("num="+num);

		long start = System.currentTimeMillis();
		long batchStartTime = start;
		long batchStartTimeOld = 0;
		long batchTime = 0;
		for(int i=0;i<num;i++){
			map.put(i, i+"_"+LocalDateTime.now());
			if(i>0 && i%100000==0){
				batchStartTimeOld = batchStartTime;
				batchStartTime = System.currentTimeMillis();
				batchTime = batchStartTime - batchStartTimeOld;
				System.out.println(i+","+batchTime);
				
			}
		}
		long end = System.currentTimeMillis();
		long time = end - start;
		
		System.out.println("time="+time);
		

		start = System.currentTimeMillis();
		s.close();
		end = System.currentTimeMillis();
		time = end - start;
		System.out.println("time2="+time);



	}
}
